home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 2
/
Deutsche Edition 2.iso
/
mac
/
POWERMAC
/
C64
/
SOURCE
/
HardDrive.c
< prev
next >
Wrap
Text File
|
1994-06-06
|
3KB
|
135 lines
/*
Commodore 64 Emulator v0.4 Earle F. Philhower III
Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Processor.h"
#include "Serial.h"
#include "HardDrive.h"
#include "Error.h"
int PetConv(int c);
void PetConvString(Str32 c);
static byte ReadMac(unsigned char *data, int secondary);
static byte WriteMac(unsigned char data, int secondary);
static byte OpenMac(char *name, int length, int secondary);
static byte CloseMac(int secondary);
static byte PutByte(byte data, int secondary);
static byte GetByte(byte *data, int secondary);
enum { NOTINUSE=0, WRITE, READ };
typedef struct
{
short fNum;
byte mode;
} FSInfo;
static FSInfo fsInfo[2];
static short dirID=0;
static byte PutByte(byte data, int secondary)
{
long len;
len=1; FSWrite(fsInfo[secondary].fNum, &len, &data);
if (len==0) return kSerialError;
else return kSerialOK;
}
static byte GetByte(byte *data, int secondary)
{
long len;
len=1; FSRead(fsInfo[secondary].fNum, &len, data);
if (len==0) return kSerialEOF;
else return kSerialOK;
}
int HardInitialize(void)
{
fsInfo[0].mode=fsInfo[1].mode=NOTINUSE;
AddSerialDevice(9, ReadMac, WriteMac, OpenMac, CloseMac, NULL);
return kNoError;
}
int PetConv(int c)
{
switch (c&0xe0)
{
case 0x40:
case 0x60:
return (c^0x20);
}
return (c);
}
void PetConvString(Str32 c)
{
int i;
for (i=1; i<c[0]+1; i++) c[i]=PetConv(c[i]);
}
static byte WriteMac(unsigned char data, int secondary)
{
if (fsInfo[secondary].mode!=WRITE) return kFloppyError;
return PutByte(data, secondary);
}
static byte ReadMac(unsigned char *data, int secondary)
{
if (fsInfo[secondary].mode!=READ) return kFloppyError;
return GetByte(data, secondary);
}
static byte OpenMac(char *name, int length, int secondary)
{
Str32 tmp;
if (fsInfo[secondary].mode!=NOTINUSE) return kFloppyError;
if ((secondary<0)||(secondary>=2)) return kFloppyError;
BlockMove(name, tmp+1, length);
tmp[0]=length;
PetConvString(tmp);
if ((fsInfo[secondary].mode=(secondary==1?WRITE:READ))==WRITE)
Create(tmp, dirID, 'C64E', 'TEXT');
if (FSOpen(tmp, dirID, &(fsInfo[secondary].fNum))!=noErr)
return kFloppyError;
return kSerialOK;
}
static byte CloseMac(int secondary)
{
switch(fsInfo[secondary].mode)
{
case WRITE:
case READ:
FSClose(fsInfo[secondary].fNum);
fsInfo[secondary].mode=NOTINUSE;
return kSerialOK;
default:
return kSerialError;
}
}
void HardChangeDirectory(void)
{
}